home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
pil50kit.zip
/
CFILES
/
PILAPI.C
< prev
next >
Wrap
Text File
|
1992-04-09
|
58KB
|
1,702 lines
/* ---------------------------------------------------------------------------- */
/* Originators: */
/* Tom Arnold, Quark, Inc., 300 S. Jackson, Denver, CO 80209 */
/* Ron Perry, Atex, Inc., 165 Lexington Road, Billerica, MA 01821 */
/* ---------------------------------------------------------------------------- */
/* The source code in this file is provided by Quark and Atex for use in the */
/* development of a Publishing Interchange Language. The code provided herein */
/* is non-proprietary, non-copyrighted, and is for use in the public domain. */
/* The source code contained herein is provided "as is". */
/* ---------------------------------------------------------------------------- */
/* QUARK AND ATEX DISCLAIM ALL WARRANTIES, EXPRESSED OR IMPLIED, WITH REGARD */
/* TO THE ENCLOSED SOURCE CODE. QUARK AND ATEX DISCLAIM ANY IMPLIED WARRANTY, */
/* INCLUDING, BUT NOT LIMITED TO ANY IMPLIED WARRANTY OF FITNESS FOR A */
/* PARTICULAR PURPOSE OR MERCHANTABILITY. */
/* ---------------------------------------------------------------------------- */
/*$ab ----------------------------- abstract ----------------------------------
pilapi.c Contains interface routines for applications to access the pil
parser and generator.
NO MEMORY IS ALLOCATED OR FREED BY THE FUNCTIONS IN THIS MODULE!
NO I/O (FILE OPENS, CLOSES, READS, OR WRITES, ERROR PRINTING)
IS DONE DIRECTLY BY THE FUNCTIONS IN THIS MODULE.
ERRORS ARE COMMUNICATED TO THE APPLICATION BY RETURNING AN
ERROR CODE AND SETTING A GLOBAL ERROR WORD WITH THAT ERROR CODE.
A function is provided to return the last PIL_ERROR set.
The functions in this module manipulate a buffer that is
provided by the application. The parser/generator functions
use memory from the buffer sequentially, and keep track of
what is used, by calling pil_alloc. However, there is no
corresponding pil_free to give back parts of the buffer. It
is the application's responsibility to provide a buffer that
is big enough for the structures being built. When the buffer
is not large enough, PIL_OUT_OF_MEMORY will be returned by
the function that requested memory. It is then up to the
application to provide a larger buffer, call pil_set_buffer,
and retry. In the case of parsing, PIL_OUT_OF_MEMORY requires
restarting the parser at the beginning of the file.
The application also provides pointers to functions to read
and write characters. The application must open the
necessary files for reading or writing the PIL, and set up the
getchar or putchar function pointers, and provide a buffer for
the parser, before calling any function here that needs to read
or write! (This is be done with pil_pg_init.)
The application can call the functions here to:
read a pil file, putting pil structures into a buffer
create pil structures in a buffer
write pil structures from the buffer to a file
write comments to a file
The functions that read or create pil structs will put structures
at the next available location in the provided buffer,
and return an error code (PIL_ERROR). A pointer to the structure
written, will be returned in a parameter passed to the function.
Major functions for parsing and generating:
------------------------------------------
pil_pg_init Initializes parser and generator
pil_get_component Read the next thing from the file and put it in
the pil buffer.
pil_put_component Write a pil_component to the open pil file
pil_create_component Create a component of the requested type in the
pil buffer at the next available location. This
allocates space in the buffer, clears it, and sets
up the structure with language-specific defaults.
Utility functions for controlling parser/generator actions:
----------------------------------------------------------
pil_set_asa_list Set up a list of application-specific-attributes
(asa) that the application wants the parser to
return, ignoring all others.
pil_set_buffer Set up the buffer that will be used for reads.
pil_set_cnt_bsize Set the content data buffering size. This value is
initialized at pil_pg_init() time and can be modified
via this function.
pil_set_getc Set get character function pointer
pil_set_putc Set put character function pointer
Utility functions for status:
----------------------------
pil_get_mem_avail Returns the number of bytes left in the pil buffer
pil_last_error Returns the most recent PIL_ERROR
pil_get_version Returns the language version and api version strings.
pil_get_line_num Returns the line number where the parser encountered
an error.
Utility functions for creating PIL data structures:
--------------------------------------------------
pil_alloc Allocates memory from the pil buffer
pil_create_asi Create an application specific item
pil_create_asa Create an application specific attribute
pil_create_pvalue A pil_value for a pil_asa
pil_create_nametbleentry A name table entry
pil_create_objid an object id (for text flow or group)
pil_create_pathpt A path point (for a pil_path)
pil_create_polypt A polygon point
pil_create_layout_start Create layout start component
pil_create_name_table Create name table component
pil_create_canvas Create canvas component
pil_create_object Create object component
pil_create_text_flow Create text flow component
pil_create_group Create group component
pil_create_layout_end Create layout end component
pil_create_content_start Create content start component
pil_create_content_hdr Create content header component
pil_create_content_data Create content data component
pil_create_content_end Create content end component
Utility functions for PIL file generation:
-----------------------------------------
pil_put_comment Write a comment into the pil file
pil_put_layout_start Write a layout start component
pil_put_name_table Write a name table component
pil_put_canvas Write a canvas component
pil_put_object Write a object component
pil_put_text_flow Write a text flow component
pil_put_group Write a group component
pil_put_layout_end Write a layout end component
pil_put_content_start Write a content start component
pil_put_content_hdr Write a content header component
pil_put_content_data Write a content data component
pil_put_content_end Write a content end component
---------------------------------------------------------------------------- */
/*$au ------------------------------ audits -----------------------------------
Author: Tom Arnold
Quark, Inc.
300 South Jackson
Denver, Colorado 80209
(303) 934-2211
Ver Date Who Etc
v01.02 24-apr-91 tla Upgraded for PIL 5.0
v01.01 03-apr-91 tla Fixed 2 bugs in pil_set_buffer, one in pil_alloc,
that could allow pointers to improper address boundaries, and allow
the buf to be overrun by several bytes. Changed pil_api_ver to b01.01
v01.00 12-feb-91 tla Initial version
---------------------------------------------------------------------------- */
/*$ep --------------------------- header files ---------------------------- */
#ifdef THINK_DA /* Support for THINK C Desk Accessory Architecture */
#include <SANE.h> /* Pickup num2str */
#else /* else */
#include <stdlib.h> /* Use stdlib for atof */
#endif /* end of THINK_DA */
#include "pildefs.h" /* Pick up PIL data structures and defines */
/*$ed ------------------------ public global data -------------------------- */
#ifdef PIL_ANSI_PROTOTYPES
ex